<?php

	require('firephp/fb.php');

	// Pull our global variable(s)
	$n2f = n2f_cls::getInstance();

	// Register extension
	$n2f->registerExtension(
		'firephp',
		'n2f_firephp',
		0.3,
		'Andrew Male',
		'http://n2framework.com/'
	);

	// Assign the notification events
	$n2f->debug->hookEvent(N2F_EVT_ERROR_THROWN, 'firephp_throwError');
	$n2f->debug->hookEvent(N2F_EVT_WARNING_THROWN, 'firephp_throwWarning');
	$n2f->debug->hookEvent(N2F_EVT_NOTICE_THROWN, 'firephp_throwNotice');

	// Start output buffering for FirePHP
	ob_start();

	// Try grabbing anything in the queue
	$errors = $n2f->debug->getErrors();
	$notices = $n2f->debug->getNotices();
	$warnings = $n2f->debug->getWarnings();

	// Check for errors
	if (count($errors) > 0) {
		foreach (array_values($errors) as $err) {
			FB::error("[#{$err['num']}] ({$err['file']}) - {$err['str']}");
		}
	}

	// Check for notices
	if (count($notices) > 0) {
		foreach (array_values($notices) as $not) {
			FB::info("[#{$not['num']}] ({$not['file']}) - {$not['str']}");
		}
	}

	// Check for warnings
	if (count($warnings) > 0) {
		foreach (array_values($warnings) as $war) {
			FB::warn("[#{$war['num']}] ({$war['file']}) - {$war['str']}");
		}
	}

	/**
	 * Throws an error message to FirePHP.
	 *
	 * @param mixed $num	Event number thrown from n2f_debug object
	 * @param string $str	Event string thrown from n2f_debug object
	 * @param string $file	Event file thrown from n2f_debug object
	 * @return null
	 */
	function firephp_throwError($num, $str, $file) {
		// Throw error message to FirePHP
		FB::error("[#{$num}] ({$file}) - {$str}");

		// Return for good measure
		return(null);
	}

	/**
	 * Throws a warning to FirePHP.
	 *
	 * @param mixed $num	Event number thrown from n2f_debug object
	 * @param string $str	Event string thrown from n2f_debug object
	 * @param string $file	Event file thrown from n2f_debug object
	 * @return null
	 */
	function firephp_throwWarning($num, $str, $file) {
		// Throw warning message to FirePHP
		FB::warn("[#{$num}] ({$file}) - {$str}");

		// Return for good measure
		return(null);
	}

	/**
	 * Throws a notice to FirePHP.
	 *
	 * @param mixed $num	Event number thrown from n2f_debug object
	 * @param string $str	Event string thrown from n2f_debug object
	 * @param string $file	Event file thrown from n2f_debug object
	 * @return null
	 */
	function firephp_throwNotice($num, $str, $file) {
		// Throw information message to FirePHP
		FB::info("[#{$num}] ({$file}) - {$str}");

		// Return for good measure
		return(null);
	}

?>